#pragma once

namespace hawking {
namespace indexlib {

#ifndef likely
#define likely(x) __builtin_expect((x), 1)
#endif

#ifndef unlikely
#define unlikely(x) __builtin_expect((x), 0)
#endif

class CallBackOnExit {
public:
    explicit CallBackOnExit(std::function<void()> cleaner) :
        cleaner_(cleaner) {}
    ~CallBackOnExit() {
        if (cleaner_) {
            cleaner_();
        }
    }

private:
    std::function<void()> cleaner_;
};

}
}